import React from 'react';
import { Button, Form, Row, Col, Upload, Icon, message, Divider } from 'antd';
import PicturesWall from '../../components/uploadImage/uploadImage'
import { getItem, setItem, removeItem } from '../../utils/store'
import axios from 'axios';
import { injectIntl } from 'react-intl';

class CompanyInfo extends React.Component{
    constructor(props) {
        super(props);
        this.postUrl=[];
        this.state = {
            data:[],
            esServiceTel:''
        }
    }

    componentDidMount(){
        if(getItem("token")){
            const userInfo = JSON.parse(getItem("token"));
            if (userInfo && userInfo.comPanyId) {
                axios.post('/api/corp/get',{
                    corpId:userInfo.comPanyId
                }).then(res => {
                    if(res && res.data){
                        this.setState({
                            data:{
                                ...res.data
                            }
                        })
                    }
                });
            }
            axios.post('/api/commParam/get',{
                name:'comm_serv_tel'
            }).then(res => {
                if(res && res.data){
                    console.log(res);
                    this.setState({
                        esServiceTel:res.data.value
                    })
                }
            });
        }
    }


    getFileIdList(value){
        if(value.length >0){
            this.postUrl = value[0]
        }
    }


    imgSave = () =>{
        const userInfo = JSON.parse(getItem("token"));
        const common = this.props.intl.messages.common;
        if (userInfo && userInfo.comPanyId && this.postUrl.length > 0) {
            axios.get('/api/corp/logo/mod', {params:{
                    id : userInfo.comPanyId,
                    logo : this.postUrl
                }
            }).then(res => {
                if(res && res.data){
                    message.success(common.modifySuccessfully);
                }
            });				
        }else{
            message.error('未修改文件');
        }
    }

    render(){
        const common = this.props.intl.messages.common;
        return (
           <div>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.EnterpriseCode}：</Col>
                    <Col span={10}>{this.state.data.id}</Col>
                </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.EnterpriseAccount}：</Col>
                    <Col span={10}>{this.state.data.account}</Col>
                </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.EnterpriseImage}：</Col>
                    <PicturesWall imgUrl={this.state.data.logo}  getFileIdList={this.getFileIdList.bind(this)}/>
                </Row>
               <Row style={{fontSize:18}}>
                   <Col span={10} offset={6}>
                       <Button type="primary"  htmlType="submit" onClick={this.imgSave}>{common.save}</Button>
                   </Col>
               </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.EnterpriseName}：</Col>
                    <Col span={10}>{this.state.data.name}</Col>
                </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.EnterpriseAddress}：</Col>
                    <Col span={10}>{this.state.data.companyAddress}</Col>
                </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.institutionsCode}：</Col>
                    <Col span={10}>{this.state.data.orgCode}</Col>
                </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.theContact}：</Col>
                    <Col span={10}>{this.state.data.chiefName}</Col>
                </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.identityCard}：</Col>
                    <Col span={10}>{this.state.data.idNo}</Col>
                </Row>
                <br/>
                <Row style={{fontSize:18}}>
                    <Col span={6}>{common.contactNumber}：</Col>
                    <Col span={10}>{this.state.data.chiefPhone}</Col>
                </Row>
                <br/><br/><br/>
                <span style={{color:'#AEAEAE',fontSize:18}}>{common.needHelpContactST}：{this.state.esServiceTel}</span>

            </div>
        );
    }
}
export default injectIntl(CompanyInfo);